package com.wander.concurrent;

public class ThreadJoinExample {
    private static int count = 0;
    private static final int num = 10000;
    private static void increment() {
        count++;
    }
    private static int getCount() {
        return count;
    }
    public static void main(String[] args) throws InterruptedException {
        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < num; i++) {
                increment();
            }
        });
        Thread thread2 = new Thread(() -> {
            for (int i = 0; i < num; i++) {
                increment();
            }
        });
        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();
        System.out.println(getCount());
    }
}
